import { defineStore } from "pinia";

export const headStore = defineStore("main", {
  state: () => ({
    isCollapse: false,
    selectMenu: [],
  }),
  actions: {
    changeCollapse() {
      this.isCollapse = !this.isCollapse;
    },
    selectMenuAction(item) {
      this.selectMenu = item;
    },
    addMenuAction(payload) {
      //对数据去重
      if (
        this.selectMenu.findIndex((item) => item.path === payload.path) === -1
      ) {
        this.selectMenu.push(payload);
      }
    },
    closeMenuAction(payload) {
      // 找到点击的索引
      const index = this.selectMenu.findIndex(
        (item) => item.name === payload.name
      );
      // 通过索引删除指定元素
      this.selectMenu.splice(index, 1);
    },
  },
});
